﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace Xinnos.Lca.Yacht.Analyzer.View
{
    /// <summary>
    /// ComponentsPanel.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class ComponentsPanel : UserControl
    {
        private ComponentsViewModel mViewModel = null;
        public ComponentsPanel()
        {
            InitializeComponent();
            if (null == mViewModel)
            {
                mViewModel = ComponentsViewModel.GetInstance();
                this.DataContext = mViewModel;
                mViewModel.PropertyChanged += this.OnPropertyChanged;
            }
        }

        public void Initialize()
        {
            assessmentPanel.Initialize();
        }

        private void OnCanExecuteNewCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }
        private void OnExecuteNewCommand(object sender, ExecutedRoutedEventArgs e)
        {
            mViewModel.Components.Add(new ComponentViewModel());
        }
        private void OnCanExecuteRemoveCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = null == mViewModel ? false : null != mViewModel.Component;
        }
        private void OnExecuteRemoveCommand(object sender, ExecutedRoutedEventArgs e)
        {
            mViewModel.Components.Remove(mViewModel.Component);
            mViewModel.Component = null;
        }

        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "Component":
                    assessmentPanel.DataContext = mViewModel.Component;
                    break;
            }
        }
    }
}
